package websocket

import (
	"github.com/gorilla/websocket"
	"sync"
)


type ConnHashMap struct {
	Map   sync.Map
}

func (chm *ConnHashMap) Set(key string, conn *websocket.Conn) {
	chm.Map.Store(key,conn)
}

func (chm *ConnHashMap) Get(key string) (*websocket.Conn,bool) {
	v,ok := chm.Map.Load(key)
  	if ok {
		return v.(*websocket.Conn),ok
	}
	return nil,false
}

func (chm *ConnHashMap)Delete(key string)  {
	chm.Map.Delete(key)
}

func (chm *ConnHashMap)Items() map[string]*websocket.Conn  {
	m :=make(map[string]*websocket.Conn,0)
	chm.Map.Range(func(k, v interface{}) bool {
		m[k.(string)] = v.(*websocket.Conn)
		return true
	})
	return m
}
